package com.yang.controller;


import com.yang.domain.DTO.AddArticleDto;
import com.yang.domain.DTO.EditArticleDto;
import com.yang.domain.Result;
import com.yang.domain.VO.ArticleVo;
import com.yang.domain.entity.Article;
import com.yang.service.ArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 后台文章控制层
 * </p>
 * @author yang
 * @date 2023/5/29
 */
@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;



    @PutMapping
    public Result edit(@RequestBody EditArticleDto articleDto){
        return articleService.edit(articleDto);
    }


    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        articleService.removeById(id);
        return Result.okResult();
    }

    @PostMapping
    public Result add(@RequestBody AddArticleDto addArticleDto){
        return articleService.addAddArticl(addArticleDto);
    }

    @GetMapping ("/list")
    public Result findAllAddArticle(Article article,Integer pageNum,Integer pageSize){
        return articleService.findAllAddArticle(article,pageNum,pageSize);
    }

    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable(value = "id") Long id){
        ArticleVo article = articleService.getInfo(id);
        return Result.okResult(article);
    }

}